package com.tancire.web.controller.market;

import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.core.page.TableDataInfo;
import com.tancire.common.enums.BusinessType;
import com.tancire.common.utils.SecurityUtils;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.net.domain.CrmCompanyIncome;
import com.tancire.net.service.ICrmCompanyIncomeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户每日收益Controller
 *
 * @author chenchao
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/mkt/income")
public class CrmCompanyIncomeMktController extends BaseController {
    @Resource
    private ICrmCompanyIncomeService crmCompanyIncomeService;

    /**
     * 查询客户每日收益列表
     */
    @PreAuthorize("@ss.hasPermi('company:user:union')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCompanyIncome crmCompanyIncome) {
        crmCompanyIncome.setCompanyId(SecurityUtils.getUserId());
        startPage();
        List<CrmCompanyIncome> list = crmCompanyIncomeService.selectCrmCompanyIncomeList(crmCompanyIncome);
        return getDataTable(list);
    }

    /**
     * 导出客户每日收益列表
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyIncome:export')")
    @Log(title = "客户每日收益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCompanyIncome crmCompanyIncome) {
        List<CrmCompanyIncome> list = crmCompanyIncomeService.selectCrmCompanyIncomeList(crmCompanyIncome);
        ExcelUtil<CrmCompanyIncome> util = new ExcelUtil<CrmCompanyIncome>(CrmCompanyIncome.class);
        util.exportExcel(response, list, "客户每日收益数据");
    }

    /**
     * 获取客户每日收益详细信息
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyIncome:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(crmCompanyIncomeService.selectCrmCompanyIncomeById(id));
    }

    /**
     * 删除客户每日收益
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyIncome:remove')")
    @Log(title = "客户每日收益", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmCompanyIncomeService.deleteCrmCompanyIncomeByIds(ids));
    }
}
